/**
 * Reformer.com Inc.
 * Copyright (c) 20017-2022 All Rights Reserved.
 */
package com.reformer.commons.utils;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 898596025@qq.com
 * @version 1.0
 * @date 2017年4月12日 下午7:25:39
 * @since 1.0
 */
public class UrlHelper {
    /**
     * 获取查询参数
     *
     * @param urlstr
     * @return
     * @throws MalformedURLException
     */
    public static Map<String, String> getQuery(String urlstr) throws MalformedURLException {
        URL url = new URL(urlstr);
        String[] kvs = url.getQuery().split("&");
        Map<String, String> map = new HashMap<String, String>();
        for (String kv : kvs) {
            String[] pair = kv.split("=");
            map.put(pair[0], pair.length > 1 ? pair[1] : "");
        }
        return map;
    }
}
